package com.netease.financial.common.util.preferences;

import com.netease.financial.common.constant.Constants;

/**
 * Created by wyf on 10/10/15.
 */
public class DebugPreferencesHelper {

    private static final String PREFERENCES_FILE_NAME = PreferencesHelper.getFullPreferenceFileName("debug");

    private static final String KEY_DOMAIN_BODY = "domain_body";
    private static final String KEY_DOMAIN_PORT = "domain_port";
    private static final String KEY_IS_DEBUG_MODE = "is_debug_mode";
    private static final String KEY_IS_TOAST_DEBUG_OPEN = "is_toast_debug_open";

    private static PreferencesHelper sPreferencesHelper;

    private static PreferencesHelper getPreferencesHelper() {
        if (sPreferencesHelper == null) {
            sPreferencesHelper = PreferencesHelper.newInstance(PREFERENCES_FILE_NAME);
        }
        return sPreferencesHelper;
    }

    public static String getDomainBody() {
        return getPreferencesHelper().getString(KEY_DOMAIN_BODY, Constants.DOMAIN_BODY);
    }

    public static String getDomainPort() {
        String port = getPreferencesHelper().getString(KEY_DOMAIN_PORT, Constants.DOMAIN_PORT);
        // 服务器会自动隐藏80端口, 此处参照服务器处理方式
        if (":80".equals(port)) {
            port = "";
        }
        return port;
    }

    public static void setDomainBody(String domainBody) {
        getPreferencesHelper().putString(KEY_DOMAIN_BODY, domainBody);
    }

    public static void setDomainPort(String domainPort) {
        getPreferencesHelper().putString(KEY_DOMAIN_PORT, domainPort);
    }

    public static boolean isDebugMode() {
        return getPreferencesHelper().getBoolean(KEY_IS_DEBUG_MODE, false);
    }

    public static void setDebugMode(boolean debugOpen) {
        getPreferencesHelper().putBoolean(KEY_IS_DEBUG_MODE, debugOpen);
    }

    public static boolean isToastDebugOpen() {
        return getPreferencesHelper().getBoolean(KEY_IS_TOAST_DEBUG_OPEN, false);
    }

    public static void setToastDebugOpen(boolean open) {
        getPreferencesHelper().putBoolean(KEY_IS_TOAST_DEBUG_OPEN, open);
    }

}
